<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.10"/>
<title>dev: dev/dev/net/SocketApi.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">dev
   &#160;<span id="projectnumber">0.2</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.10 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('_socket_api_8hpp_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">SocketApi.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/******************************************************************************</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * Name         : SocketApi.hpp</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> * Author       : 671643387</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * Date         : Aug 27, 2015</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * Description  : 套接字APIs</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> *****************************************************************************/</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;</div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#ifndef SOCKETAPI_HPP_</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#define SOCKETAPI_HPP_</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;</div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &lt;stdint.h&gt;</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;</div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#if defined(__WINDOWS__)</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="preprocessor">#   if defined(_WIN64)</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="preprocessor">#pragma warning(disable:4267)</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="preprocessor">#   endif</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="preprocessor">#include &lt;WinSock2.h&gt;</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor">#include &lt;ws2tcpip.h&gt;</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="preprocessor">#elif defined(__LINUX__)</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="preprocessor">#include &lt;sys/socket.h&gt;</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#include &lt;sys/sendfile.h&gt;</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#include &lt;sys/epoll.h&gt;</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="preprocessor">#include &lt;sys/time.h&gt;</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="preprocessor">#include &lt;sys/select.h&gt;</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="preprocessor">#include &lt;arpa/inet.h&gt;</span></div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="preprocessor">#include &lt;netdb.h&gt;</span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="preprocessor">#include &lt;unistd.h&gt;</span></div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="preprocessor">#include &lt;fcntl.h&gt;</span></div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="preprocessor">#if defined(__WINDOWS__)</span></div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;<span class="preprocessor">#   ifndef _SSIZE_T</span></div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;<span class="preprocessor">#   define _SSIZE_T</span></div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;<span class="keyword">typedef</span> <span class="keywordtype">signed</span> <span class="keywordtype">int</span> ssize_t;</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<span class="preprocessor">#   endif</span></div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacedev.html">dev</a></div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;{</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    <span class="keyword">namespace </span>net</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    {</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;<span class="preprocessor">#if defined(__WINDOWS__)</span></div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        <span class="keyword">typedef</span> SOCKET  sock_t;</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;        <span class="keyword">typedef</span> <span class="keywordtype">int</span> socklen_t;</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;<span class="preprocessor">#elif defined(__LINUX__)</span></div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;        <span class="keyword">typedef</span> <span class="keywordtype">int</span>     sock_t;</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;        <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> SOCKET_ERROR = -1;</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;        <span class="keyword">static</span> <span class="keyword">const</span> sock_t INVALID_SOCKET = -1;</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;        <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> SOCKET_ERROR_WOULDBLOCK = -500;</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;</div>
<div class="line"><a name="l00057"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html">   57</a></span>&#160;        <span class="keyword">class </span><a class="code" href="classdev_1_1net_1_1_socket_api.html">SocketApi</a></div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;        {</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;        <span class="keyword">public</span>:</div>
<div class="line"><a name="l00067"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a468438c9663cdc534e3bf628c29e7c75">   67</a></span>&#160;            <span class="keyword">static</span> sock_t <a class="code" href="classdev_1_1net_1_1_socket_api.html#a468438c9663cdc534e3bf628c29e7c75">socket</a>(<span class="keywordtype">int</span> domain, <span class="keywordtype">int</span> type, <span class="keywordtype">int</span> protocol = 0)</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;            {</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;                return ::socket(domain, type, protocol);</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;            }</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;</div>
<div class="line"><a name="l00079"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#ab9e728b6cb0b7932e73acbb250489e25">   79</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#ab9e728b6cb0b7932e73acbb250489e25">bind</a>(sock_t sockfd, <span class="keyword">const</span> <span class="keyword">struct</span> sockaddr* addr, socklen_t addrlen)</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;            {</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;                <span class="keywordflow">return</span> (0 == ::<a class="code" href="classdev_1_1net_1_1_socket_api.html#ab9e728b6cb0b7932e73acbb250489e25">bind</a>(sockfd, addr, addrlen));</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;            }</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;</div>
<div class="line"><a name="l00090"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a0cc819e43ff24147028aecbe7258b08e">   90</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#a0cc819e43ff24147028aecbe7258b08e">listen</a>(sock_t sockfd, <span class="keywordtype">int</span> backlog)</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;            {</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;                <span class="keywordflow">return</span> (0 == ::<a class="code" href="classdev_1_1net_1_1_socket_api.html#a0cc819e43ff24147028aecbe7258b08e">listen</a>(sockfd, backlog));</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;            }</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;</div>
<div class="line"><a name="l00102"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a2e9851418b2c871852e441f73c1df495">  102</a></span>&#160;            <span class="keyword">static</span> sock_t <a class="code" href="classdev_1_1net_1_1_socket_api.html#a2e9851418b2c871852e441f73c1df495">accept</a>(sock_t sockfd, <span class="keyword">struct</span> sockaddr* addr, socklen_t* addrlen)</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;            {</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;                return ::accept(sockfd, addr, addrlen);</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;            }</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;</div>
<div class="line"><a name="l00114"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a4ac36cc16daf7f35ac40e70fdd52391b">  114</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#a4ac36cc16daf7f35ac40e70fdd52391b">connect</a>(sock_t sockfd, <span class="keyword">const</span> <span class="keyword">struct</span> sockaddr* addr, socklen_t addrlen)</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;            {</div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;                <span class="keywordflow">return</span> (0 == ::<a class="code" href="classdev_1_1net_1_1_socket_api.html#a4ac36cc16daf7f35ac40e70fdd52391b">connect</a>(sockfd, addr, addrlen));</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;            }</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;</div>
<div class="line"><a name="l00124"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#acab670d7ff1243462f782676d5f26931">  124</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#acab670d7ff1243462f782676d5f26931">close</a>(sock_t sockfd)</div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;            {</div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;<span class="preprocessor">#if defined(__LINUX__)</span></div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;                <span class="keywordflow">return</span> (0 == ::<a class="code" href="classdev_1_1net_1_1_socket_api.html#acab670d7ff1243462f782676d5f26931">close</a>(sockfd));</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;<span class="preprocessor">#elif defined(__WINDOWS__)</span></div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;                <span class="keywordflow">return</span> (0 == ::closesocket(sockfd));</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;            }</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;</div>
<div class="line"><a name="l00139"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#aca13c6bb87f3118f3dd2c008238e3a5a">  139</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#aca13c6bb87f3118f3dd2c008238e3a5a">shutdown</a>(sock_t sockfd, <span class="keywordtype">int</span> how)</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;            {</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;                <span class="keywordflow">return</span> (0 == ::<a class="code" href="classdev_1_1net_1_1_socket_api.html#aca13c6bb87f3118f3dd2c008238e3a5a">shutdown</a>(sockfd, how));</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;            }</div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;</div>
<div class="line"><a name="l00154"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#adea576bbc110685fbf0bd1faa36dd1f6">  154</a></span>&#160;            <span class="keyword">static</span> ssize_t <a class="code" href="classdev_1_1net_1_1_socket_api.html#adea576bbc110685fbf0bd1faa36dd1f6">recvfrom</a>(sock_t sockfd, <span class="keywordtype">void</span>* buffer, <span class="keywordtype">size_t</span> length, <span class="keywordtype">int</span> flags,</div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;            <span class="keyword">struct</span> sockaddr* src_addr, socklen_t* addrlen)</div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;            {</div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;<span class="preprocessor">#if defined(__LINUX__)</span></div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;                return ::recvfrom(sockfd, buffer, length, flags, src_addr,</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;                    addrlen);</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;<span class="preprocessor">#elif defined(__WINDOWS__)</span></div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;                return ::recvfrom(sockfd, (<span class="keywordtype">char</span>*)buffer, length, flags,</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;                    src_addr, addrlen);</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;            }</div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;</div>
<div class="line"><a name="l00176"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a74d39e1ca0169a15f8e4cc6c6f9756ab">  176</a></span>&#160;            <span class="keyword">static</span> ssize_t <a class="code" href="classdev_1_1net_1_1_socket_api.html#a74d39e1ca0169a15f8e4cc6c6f9756ab">sendto</a>(sock_t sockfd, <span class="keywordtype">void</span>* buffer, <span class="keywordtype">size_t</span> length, <span class="keywordtype">int</span> flags,</div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;            <span class="keyword">struct</span> sockaddr* dest_addr, socklen_t addrlen)</div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;            {</div>
<div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;<span class="preprocessor">#if defined(__LINUX__)</span></div>
<div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;                return ::sendto(sockfd, buffer, length, flags, dest_addr,</div>
<div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;                    addrlen);</div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;<span class="preprocessor">#elif defined(__WINDOWS__)</span></div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;                return ::sendto(sockfd, (<span class="keywordtype">char</span>*)buffer, length, flags,</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;                    dest_addr, addrlen);</div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;</div>
<div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;            }</div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;</div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;<span class="preprocessor">#if defined(__LINUX__)</span></div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;</div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> socketpair(<span class="keywordtype">int</span> domain, <span class="keywordtype">int</span> type, <span class="keywordtype">int</span> protocol, sock_t sockfd[2])</div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;            {</div>
<div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;                <span class="keywordflow">return</span> (0 == ::socketpair(domain, type, protocol, sockfd));</div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;            }</div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;</div>
<div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;            <span class="keyword">static</span> ssize_t sendfile(sock_t sockfd, <span class="keywordtype">int</span> in_fd, off_t* offset, <span class="keywordtype">size_t</span> count)</div>
<div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;            {</div>
<div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;                return ::sendfile(sockfd, in_fd, offset, count);</div>
<div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160;            }</div>
<div class="line"><a name="l00215"></a><span class="lineno">  215</span>&#160;</div>
<div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;            <span class="keyword">static</span> <span class="keywordtype">int</span> epoll_create(<span class="keywordtype">int</span> size)</div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;            {</div>
<div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;                return ::epoll_create(size);</div>
<div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;            }</div>
<div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;</div>
<div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> epoll_ctl(<span class="keywordtype">int</span> epfd, <span class="keywordtype">int</span> op, <span class="keywordtype">int</span> fd, <span class="keyword">struct</span> epoll_event* ev)</div>
<div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;            {</div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;                <span class="keywordflow">return</span> (0 == ::epoll_ctl(epfd, op, fd, ev));</div>
<div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;            }</div>
<div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;</div>
<div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;            <span class="keyword">static</span> <span class="keywordtype">int</span> epoll_wait(<span class="keywordtype">int</span> epfd, <span class="keyword">struct</span> epoll_event* evlist, <span class="keywordtype">int</span> maxevents,</div>
<div class="line"><a name="l00248"></a><span class="lineno">  248</span>&#160;                <span class="keywordtype">int</span> timeout)</div>
<div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160;            {</div>
<div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;                return ::epoll_wait(epfd, evlist, maxevents, timeout);</div>
<div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;            }</div>
<div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;</div>
<div class="line"><a name="l00262"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#ab5620cca4671a803d43ff11cddd29430">  262</a></span>&#160;            <span class="keyword">static</span> ssize_t <a class="code" href="classdev_1_1net_1_1_socket_api.html#ab5620cca4671a803d43ff11cddd29430">recv</a>(sock_t sockfd, <span class="keywordtype">void</span>* buffer, <span class="keywordtype">size_t</span> length, <span class="keywordtype">int</span> flags)</div>
<div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;            {</div>
<div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;<span class="preprocessor">#if defined(__LINUX__)</span></div>
<div class="line"><a name="l00265"></a><span class="lineno">  265</span>&#160;                return ::recv (sockfd, buffer, length, flags);</div>
<div class="line"><a name="l00266"></a><span class="lineno">  266</span>&#160;<span class="preprocessor">#elif defined(__WINDOWS__)</span></div>
<div class="line"><a name="l00267"></a><span class="lineno">  267</span>&#160;                return ::recv(sockfd, (<span class="keywordtype">char</span>*)buffer, length, flags);</div>
<div class="line"><a name="l00268"></a><span class="lineno">  268</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;            }</div>
<div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;</div>
<div class="line"><a name="l00279"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a6747c98d432dda18d52ca8602d5c024c">  279</a></span>&#160;            <span class="keyword">static</span> ssize_t <a class="code" href="classdev_1_1net_1_1_socket_api.html#a6747c98d432dda18d52ca8602d5c024c">send</a>(sock_t sockfd, <span class="keyword">const</span> <span class="keywordtype">void</span>* buffer, <span class="keywordtype">size_t</span> length, <span class="keywordtype">int</span> flags)</div>
<div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;            {</div>
<div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;<span class="preprocessor">#if defined(__LINUX__)</span></div>
<div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;                return ::send (sockfd, buffer, length, flags);</div>
<div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;<span class="preprocessor">#elif defined(__WINDOWS__)</span></div>
<div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;                return ::send(sockfd, (<span class="keywordtype">char</span>*)buffer, length, flags);</div>
<div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;            }</div>
<div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;</div>
<div class="line"><a name="l00293"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a2dadafc2cc647d97ab5091e8dc12195c">  293</a></span>&#160;            <span class="keyword">static</span> uint16_t <a class="code" href="classdev_1_1net_1_1_socket_api.html#a2dadafc2cc647d97ab5091e8dc12195c">htons</a>(uint16_t host_uint16)</div>
<div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;            {</div>
<div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;                return ::htons(host_uint16);</div>
<div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;            }</div>
<div class="line"><a name="l00297"></a><span class="lineno">  297</span>&#160;</div>
<div class="line"><a name="l00303"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a349f48bfc1f677bc3361a0be8ab47783">  303</a></span>&#160;            <span class="keyword">static</span> uint32_t <a class="code" href="classdev_1_1net_1_1_socket_api.html#a349f48bfc1f677bc3361a0be8ab47783">htonl</a>(uint32_t host_uint32)</div>
<div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;            {</div>
<div class="line"><a name="l00305"></a><span class="lineno">  305</span>&#160;                return ::htonl(host_uint32);</div>
<div class="line"><a name="l00306"></a><span class="lineno">  306</span>&#160;            }</div>
<div class="line"><a name="l00307"></a><span class="lineno">  307</span>&#160;</div>
<div class="line"><a name="l00313"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a4dd6d37153baf0f3b28a1a86e9e3513b">  313</a></span>&#160;            <span class="keyword">static</span> uint16_t <a class="code" href="classdev_1_1net_1_1_socket_api.html#a4dd6d37153baf0f3b28a1a86e9e3513b">ntohs</a>(uint16_t net_uint16)</div>
<div class="line"><a name="l00314"></a><span class="lineno">  314</span>&#160;            {</div>
<div class="line"><a name="l00315"></a><span class="lineno">  315</span>&#160;                return ::ntohs(net_uint16);</div>
<div class="line"><a name="l00316"></a><span class="lineno">  316</span>&#160;            }</div>
<div class="line"><a name="l00317"></a><span class="lineno">  317</span>&#160;</div>
<div class="line"><a name="l00323"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#ab645166633b0002c46951033027d022c">  323</a></span>&#160;            <span class="keyword">static</span> uint32_t <a class="code" href="classdev_1_1net_1_1_socket_api.html#ab645166633b0002c46951033027d022c">ntohl</a>(uint32_t net_uint32)</div>
<div class="line"><a name="l00324"></a><span class="lineno">  324</span>&#160;            {</div>
<div class="line"><a name="l00325"></a><span class="lineno">  325</span>&#160;                return ::ntohl(net_uint32);</div>
<div class="line"><a name="l00326"></a><span class="lineno">  326</span>&#160;            }</div>
<div class="line"><a name="l00327"></a><span class="lineno">  327</span>&#160;</div>
<div class="line"><a name="l00335"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a191d49266fd9aa8149240009fa204e98">  335</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#a191d49266fd9aa8149240009fa204e98">inet_pton</a>(<span class="keywordtype">int</span> domain, <span class="keyword">const</span> <span class="keywordtype">char</span>* src_str, <span class="keywordtype">void</span>* addrptr)</div>
<div class="line"><a name="l00336"></a><span class="lineno">  336</span>&#160;            {</div>
<div class="line"><a name="l00337"></a><span class="lineno">  337</span>&#160;<span class="preprocessor">#if defined(__LINUX__)</span></div>
<div class="line"><a name="l00338"></a><span class="lineno">  338</span>&#160;                return ::inet_pton (domain, src_str, addrptr);</div>
<div class="line"><a name="l00339"></a><span class="lineno">  339</span>&#160;<span class="preprocessor">#elif defined(__WINDOWS__)</span></div>
<div class="line"><a name="l00340"></a><span class="lineno">  340</span>&#160;                in_addr* pAddr = (in_addr*)addrptr;</div>
<div class="line"><a name="l00341"></a><span class="lineno">  341</span>&#160;                pAddr-&gt;S_un.S_addr = ::inet_addr(src_str);</div>
<div class="line"><a name="l00342"></a><span class="lineno">  342</span>&#160;                <span class="keywordflow">return</span> 1;</div>
<div class="line"><a name="l00343"></a><span class="lineno">  343</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00344"></a><span class="lineno">  344</span>&#160;            }</div>
<div class="line"><a name="l00345"></a><span class="lineno">  345</span>&#160;</div>
<div class="line"><a name="l00354"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a3ae6728572945a50592d06e06ca1681c">  354</a></span>&#160;            <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="classdev_1_1net_1_1_socket_api.html#a3ae6728572945a50592d06e06ca1681c">inet_ntop</a>(<span class="keywordtype">int</span> domain, <span class="keyword">const</span> <span class="keywordtype">void</span>* addrptr, <span class="keywordtype">char</span>* dst_ptr,</div>
<div class="line"><a name="l00355"></a><span class="lineno">  355</span>&#160;                <span class="keywordtype">size_t</span> len)</div>
<div class="line"><a name="l00356"></a><span class="lineno">  356</span>&#160;            {</div>
<div class="line"><a name="l00357"></a><span class="lineno">  357</span>&#160;<span class="preprocessor">#if defined(__LINUX__)</span></div>
<div class="line"><a name="l00358"></a><span class="lineno">  358</span>&#160;                return ::inet_ntop (domain, addrptr, dst_ptr, len);</div>
<div class="line"><a name="l00359"></a><span class="lineno">  359</span>&#160;<span class="preprocessor">#elif defined(__WINDOWS__)</span></div>
<div class="line"><a name="l00360"></a><span class="lineno">  360</span>&#160;                <span class="keywordtype">char</span>* pStr = ::inet_ntoa(*(in_addr*)addrptr);</div>
<div class="line"><a name="l00361"></a><span class="lineno">  361</span>&#160;                strcpy_s(dst_ptr, len, pStr);</div>
<div class="line"><a name="l00362"></a><span class="lineno">  362</span>&#160;                <span class="keywordflow">return</span> dst_ptr;</div>
<div class="line"><a name="l00363"></a><span class="lineno">  363</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00364"></a><span class="lineno">  364</span>&#160;            }</div>
<div class="line"><a name="l00365"></a><span class="lineno">  365</span>&#160;</div>
<div class="line"><a name="l00374"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#ac30763c26a24cd674efa9e6804d9e448">  374</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#ac30763c26a24cd674efa9e6804d9e448">getaddrinfo</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* host, <span class="keyword">const</span> <span class="keywordtype">char</span>* service,</div>
<div class="line"><a name="l00375"></a><span class="lineno">  375</span>&#160;                <span class="keyword">const</span> <span class="keyword">struct</span> addrinfo* hints, <span class="keyword">struct</span> addrinfo** result)</div>
<div class="line"><a name="l00376"></a><span class="lineno">  376</span>&#160;            {</div>
<div class="line"><a name="l00377"></a><span class="lineno">  377</span>&#160;                <span class="keywordflow">return</span> (0 == ::<a class="code" href="classdev_1_1net_1_1_socket_api.html#ac30763c26a24cd674efa9e6804d9e448">getaddrinfo</a>(host, service, hints, result));</div>
<div class="line"><a name="l00378"></a><span class="lineno">  378</span>&#160;            }</div>
<div class="line"><a name="l00379"></a><span class="lineno">  379</span>&#160;</div>
<div class="line"><a name="l00384"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a2139efc71f04f29f6cd6d47217a68fc6">  384</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#a2139efc71f04f29f6cd6d47217a68fc6">freeaddrinfo</a>(<span class="keyword">struct</span> addrinfo* result)</div>
<div class="line"><a name="l00385"></a><span class="lineno">  385</span>&#160;            {</div>
<div class="line"><a name="l00386"></a><span class="lineno">  386</span>&#160;                <a class="code" href="classdev_1_1net_1_1_socket_api.html#a2139efc71f04f29f6cd6d47217a68fc6">::freeaddrinfo</a>(result);</div>
<div class="line"><a name="l00387"></a><span class="lineno">  387</span>&#160;            }</div>
<div class="line"><a name="l00388"></a><span class="lineno">  388</span>&#160;</div>
<div class="line"><a name="l00400"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a6137e6bc83ca8599a0e87c7534808c62">  400</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#a6137e6bc83ca8599a0e87c7534808c62">getnameinfo</a>(<span class="keyword">const</span> <span class="keyword">struct</span> sockaddr* addr, socklen_t addrlen,</div>
<div class="line"><a name="l00401"></a><span class="lineno">  401</span>&#160;                <span class="keywordtype">char</span>* host, <span class="keywordtype">size_t</span> hostlen, <span class="keywordtype">char</span>* service, <span class="keywordtype">size_t</span> servlen, <span class="keywordtype">int</span> flags)</div>
<div class="line"><a name="l00402"></a><span class="lineno">  402</span>&#160;            {</div>
<div class="line"><a name="l00403"></a><span class="lineno">  403</span>&#160;                <span class="keywordflow">return</span> (0 == ::<a class="code" href="classdev_1_1net_1_1_socket_api.html#a6137e6bc83ca8599a0e87c7534808c62">getnameinfo</a>(addr, addrlen, host, hostlen, service,</div>
<div class="line"><a name="l00404"></a><span class="lineno">  404</span>&#160;                    servlen, flags));</div>
<div class="line"><a name="l00405"></a><span class="lineno">  405</span>&#160;            }</div>
<div class="line"><a name="l00406"></a><span class="lineno">  406</span>&#160;</div>
<div class="line"><a name="l00414"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#acdaa0a5aadc721422f748f8f931daa53">  414</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#acdaa0a5aadc721422f748f8f931daa53">getsockname</a>(sock_t sockfd, <span class="keyword">struct</span> sockaddr* addr,</div>
<div class="line"><a name="l00415"></a><span class="lineno">  415</span>&#160;                socklen_t* addrlen)</div>
<div class="line"><a name="l00416"></a><span class="lineno">  416</span>&#160;            {</div>
<div class="line"><a name="l00417"></a><span class="lineno">  417</span>&#160;                <span class="keywordflow">return</span> (0 == ::<a class="code" href="classdev_1_1net_1_1_socket_api.html#acdaa0a5aadc721422f748f8f931daa53">getsockname</a>(sockfd, addr, addrlen));</div>
<div class="line"><a name="l00418"></a><span class="lineno">  418</span>&#160;            }</div>
<div class="line"><a name="l00419"></a><span class="lineno">  419</span>&#160;</div>
<div class="line"><a name="l00427"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#afb96ed718ee882239929e15f68f4cfa1">  427</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#afb96ed718ee882239929e15f68f4cfa1">getpeername</a>(sock_t sockfd, <span class="keyword">struct</span> sockaddr* addr,</div>
<div class="line"><a name="l00428"></a><span class="lineno">  428</span>&#160;                socklen_t* addrlen)</div>
<div class="line"><a name="l00429"></a><span class="lineno">  429</span>&#160;            {</div>
<div class="line"><a name="l00430"></a><span class="lineno">  430</span>&#160;                <span class="keywordflow">return</span> (0 == ::<a class="code" href="classdev_1_1net_1_1_socket_api.html#afb96ed718ee882239929e15f68f4cfa1">getpeername</a>(sockfd, addr, addrlen));</div>
<div class="line"><a name="l00431"></a><span class="lineno">  431</span>&#160;            }</div>
<div class="line"><a name="l00432"></a><span class="lineno">  432</span>&#160;</div>
<div class="line"><a name="l00442"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a508935c561a3841e65d6a7e794503758">  442</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#a508935c561a3841e65d6a7e794503758">getsockopt</a>(sock_t sockfd, <span class="keywordtype">int</span> level, <span class="keywordtype">int</span> optname, <span class="keywordtype">void</span>* optval,</div>
<div class="line"><a name="l00443"></a><span class="lineno">  443</span>&#160;                socklen_t* optlen)</div>
<div class="line"><a name="l00444"></a><span class="lineno">  444</span>&#160;            {</div>
<div class="line"><a name="l00445"></a><span class="lineno">  445</span>&#160;<span class="preprocessor">#if defined(__LINUX__)</span></div>
<div class="line"><a name="l00446"></a><span class="lineno">  446</span>&#160;                <span class="keywordflow">return</span> (0  == ::<a class="code" href="classdev_1_1net_1_1_socket_api.html#a508935c561a3841e65d6a7e794503758">getsockopt</a> (sockfd, level, optname, optval, optlen));</div>
<div class="line"><a name="l00447"></a><span class="lineno">  447</span>&#160;<span class="preprocessor">#elif defined(__WINDOWS__)</span></div>
<div class="line"><a name="l00448"></a><span class="lineno">  448</span>&#160;                <span class="keywordflow">return</span> (0 == ::<a class="code" href="classdev_1_1net_1_1_socket_api.html#a508935c561a3841e65d6a7e794503758">getsockopt</a>(sockfd, level, optname, (<span class="keywordtype">char</span>*)optval, optlen));</div>
<div class="line"><a name="l00449"></a><span class="lineno">  449</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00450"></a><span class="lineno">  450</span>&#160;            }</div>
<div class="line"><a name="l00451"></a><span class="lineno">  451</span>&#160;</div>
<div class="line"><a name="l00461"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#aebfd2453f8424cebb9dc467d1cea40dd">  461</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#aebfd2453f8424cebb9dc467d1cea40dd">setsockopt</a>(sock_t sockfd, <span class="keywordtype">int</span> level, <span class="keywordtype">int</span> optname,</div>
<div class="line"><a name="l00462"></a><span class="lineno">  462</span>&#160;                <span class="keyword">const</span> <span class="keywordtype">void</span>* optval, socklen_t optlen)</div>
<div class="line"><a name="l00463"></a><span class="lineno">  463</span>&#160;            {</div>
<div class="line"><a name="l00464"></a><span class="lineno">  464</span>&#160;<span class="preprocessor">#if defined(__LINUX__)</span></div>
<div class="line"><a name="l00465"></a><span class="lineno">  465</span>&#160;                <span class="keywordflow">return</span> (0 == ::<a class="code" href="classdev_1_1net_1_1_socket_api.html#aebfd2453f8424cebb9dc467d1cea40dd">setsockopt</a> (sockfd, level, optname, optval, optlen));</div>
<div class="line"><a name="l00466"></a><span class="lineno">  466</span>&#160;<span class="preprocessor">#elif defined(__WINDOWS__)</span></div>
<div class="line"><a name="l00467"></a><span class="lineno">  467</span>&#160;                <span class="keywordflow">return</span> (0 == ::<a class="code" href="classdev_1_1net_1_1_socket_api.html#aebfd2453f8424cebb9dc467d1cea40dd">setsockopt</a>(sockfd, level, optname,</div>
<div class="line"><a name="l00468"></a><span class="lineno">  468</span>&#160;                    (<span class="keyword">const</span> <span class="keywordtype">char</span>*)optval, optlen));</div>
<div class="line"><a name="l00469"></a><span class="lineno">  469</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00470"></a><span class="lineno">  470</span>&#160;            }</div>
<div class="line"><a name="l00471"></a><span class="lineno">  471</span>&#160;</div>
<div class="line"><a name="l00481"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#af8c6ff0f1ef50696e975920048a4ebf9">  481</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#af8c6ff0f1ef50696e975920048a4ebf9">select</a>(<span class="keywordtype">int</span> nfds, fd_set* readfds, fd_set* writefds,</div>
<div class="line"><a name="l00482"></a><span class="lineno">  482</span>&#160;                fd_set* exceptfds, <span class="keyword">struct</span> timeval* timeout)</div>
<div class="line"><a name="l00483"></a><span class="lineno">  483</span>&#160;            {</div>
<div class="line"><a name="l00484"></a><span class="lineno">  484</span>&#160;                return ::select(nfds, readfds, writefds, exceptfds, timeout);</div>
<div class="line"><a name="l00485"></a><span class="lineno">  485</span>&#160;            }</div>
<div class="line"><a name="l00486"></a><span class="lineno">  486</span>&#160;</div>
<div class="line"><a name="l00494"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#af0cdd3c603edd23ef36f104ef3179394">  494</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#af0cdd3c603edd23ef36f104ef3179394">ioctlsocket</a>(sock_t sock, <span class="keywordtype">long</span> cmd, u_long* argp)</div>
<div class="line"><a name="l00495"></a><span class="lineno">  495</span>&#160;            {</div>
<div class="line"><a name="l00496"></a><span class="lineno">  496</span>&#160;<span class="preprocessor">#if defined(__WINDOWS__)</span></div>
<div class="line"><a name="l00497"></a><span class="lineno">  497</span>&#160;                return ::ioctlsocket(sock, cmd, argp);</div>
<div class="line"><a name="l00498"></a><span class="lineno">  498</span>&#160;<span class="preprocessor">#elif defined(__LINUX__)</span></div>
<div class="line"><a name="l00499"></a><span class="lineno">  499</span>&#160;                <span class="keywordflow">return</span> -1;</div>
<div class="line"><a name="l00500"></a><span class="lineno">  500</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00501"></a><span class="lineno">  501</span>&#160;            }</div>
<div class="line"><a name="l00502"></a><span class="lineno">  502</span>&#160;</div>
<div class="line"><a name="l00509"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#a14bf28751003dc86e20c60182e771e55">  509</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#a14bf28751003dc86e20c60182e771e55">setsocketnoblocking</a>(sock_t sock, <span class="keywordtype">bool</span> on)</div>
<div class="line"><a name="l00510"></a><span class="lineno">  510</span>&#160;            {</div>
<div class="line"><a name="l00511"></a><span class="lineno">  511</span>&#160;<span class="preprocessor">#if defined(__WINDOWS__)</span></div>
<div class="line"><a name="l00512"></a><span class="lineno">  512</span>&#160;                u_long arg = (on) ? 1 : 0;</div>
<div class="line"><a name="l00513"></a><span class="lineno">  513</span>&#160;                <span class="keywordflow">return</span> (0 == ::<a class="code" href="classdev_1_1net_1_1_socket_api.html#af0cdd3c603edd23ef36f104ef3179394">ioctlsocket</a>(sock, FIONBIO, &amp;arg));</div>
<div class="line"><a name="l00514"></a><span class="lineno">  514</span>&#160;<span class="preprocessor">#elif defined(__LINUX__)</span></div>
<div class="line"><a name="l00515"></a><span class="lineno">  515</span>&#160;                <span class="keywordtype">int</span> flags = fcntl(sock, F_GETFL, 0);</div>
<div class="line"><a name="l00516"></a><span class="lineno">  516</span>&#160;                <span class="keywordflow">if</span> (on) flags |= O_NONBLOCK;</div>
<div class="line"><a name="l00517"></a><span class="lineno">  517</span>&#160;                <span class="keywordflow">else</span> flags &amp;= ~O_NONBLOCK;</div>
<div class="line"><a name="l00518"></a><span class="lineno">  518</span>&#160;                <span class="keywordflow">return</span> (-1 != fcntl(sock, F_SETFL, flags));</div>
<div class="line"><a name="l00519"></a><span class="lineno">  519</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00520"></a><span class="lineno">  520</span>&#160;            }</div>
<div class="line"><a name="l00521"></a><span class="lineno">  521</span>&#160;</div>
<div class="line"><a name="l00528"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_socket_api.html#af2941c088aaa168f045e516f1710e54b">  528</a></span>&#160;            <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#af2941c088aaa168f045e516f1710e54b">setsocketlinger</a>(sock_t sock, <span class="keywordtype">bool</span> on)</div>
<div class="line"><a name="l00529"></a><span class="lineno">  529</span>&#160;            {</div>
<div class="line"><a name="l00530"></a><span class="lineno">  530</span>&#160;                <span class="keyword">struct </span>linger ling;</div>
<div class="line"><a name="l00531"></a><span class="lineno">  531</span>&#160;                ling.l_onoff = on ? 1 : 0;</div>
<div class="line"><a name="l00532"></a><span class="lineno">  532</span>&#160;                ling.l_linger = 0;</div>
<div class="line"><a name="l00533"></a><span class="lineno">  533</span>&#160;                <span class="keywordflow">return</span> <a class="code" href="classdev_1_1net_1_1_socket_api.html#aebfd2453f8424cebb9dc467d1cea40dd">SocketApi::setsockopt</a>(sock, SOL_SOCKET, SO_LINGER, &amp;ling, <span class="keyword">sizeof</span>(ling));</div>
<div class="line"><a name="l00534"></a><span class="lineno">  534</span>&#160;            }</div>
<div class="line"><a name="l00535"></a><span class="lineno">  535</span>&#160;        };</div>
<div class="line"><a name="l00536"></a><span class="lineno">  536</span>&#160;    }</div>
<div class="line"><a name="l00537"></a><span class="lineno">  537</span>&#160;}</div>
<div class="line"><a name="l00538"></a><span class="lineno">  538</span>&#160;</div>
<div class="line"><a name="l00539"></a><span class="lineno">  539</span>&#160;<span class="preprocessor">#endif </span><span class="comment">/* SOCKETAPI_HPP_ */</span><span class="preprocessor"></span></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_ab5620cca4671a803d43ff11cddd29430"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#ab5620cca4671a803d43ff11cddd29430">dev::net::SocketApi::recv</a></div><div class="ttdeci">static ssize_t recv(sock_t sockfd, void *buffer, size_t length, int flags)</div><div class="ttdoc">接受数据 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:262</div></div>
<div class="ttc" id="namespacedev_html"><div class="ttname"><a href="namespacedev.html">dev</a></div><div class="ttdef"><b>Definition:</b> Atomic.hpp:18</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a6747c98d432dda18d52ca8602d5c024c"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a6747c98d432dda18d52ca8602d5c024c">dev::net::SocketApi::send</a></div><div class="ttdeci">static ssize_t send(sock_t sockfd, const void *buffer, size_t length, int flags)</div><div class="ttdoc">发送数据 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:279</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_acab670d7ff1243462f782676d5f26931"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#acab670d7ff1243462f782676d5f26931">dev::net::SocketApi::close</a></div><div class="ttdeci">static bool close(sock_t sockfd)</div><div class="ttdoc">关闭指定套接字 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:124</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_af0cdd3c603edd23ef36f104ef3179394"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#af0cdd3c603edd23ef36f104ef3179394">dev::net::SocketApi::ioctlsocket</a></div><div class="ttdeci">static int ioctlsocket(sock_t sock, long cmd, u_long *argp)</div><div class="ttdoc">设置套接字IO模型 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:494</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a349f48bfc1f677bc3361a0be8ab47783"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a349f48bfc1f677bc3361a0be8ab47783">dev::net::SocketApi::htonl</a></div><div class="ttdeci">static uint32_t htonl(uint32_t host_uint32)</div><div class="ttdoc">主机字节序转换为网络字节序 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:303</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a2139efc71f04f29f6cd6d47217a68fc6"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a2139efc71f04f29f6cd6d47217a68fc6">dev::net::SocketApi::freeaddrinfo</a></div><div class="ttdeci">static void freeaddrinfo(struct addrinfo *result)</div><div class="ttdoc">释放getaddrinfo返回的数据 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:384</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a0cc819e43ff24147028aecbe7258b08e"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a0cc819e43ff24147028aecbe7258b08e">dev::net::SocketApi::listen</a></div><div class="ttdeci">static bool listen(sock_t sockfd, int backlog)</div><div class="ttdoc">在指定套接字上启动监听 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:90</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a3ae6728572945a50592d06e06ca1681c"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a3ae6728572945a50592d06e06ca1681c">dev::net::SocketApi::inet_ntop</a></div><div class="ttdeci">static const char * inet_ntop(int domain, const void *addrptr, char *dst_ptr, size_t len)</div><div class="ttdoc">转换二进制格式的地址为点分十进制表示 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:354</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_afb96ed718ee882239929e15f68f4cfa1"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#afb96ed718ee882239929e15f68f4cfa1">dev::net::SocketApi::getpeername</a></div><div class="ttdeci">static bool getpeername(sock_t sockfd, struct sockaddr *addr, socklen_t *addrlen)</div><div class="ttdoc">获取套接字远程地址 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:427</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_ab645166633b0002c46951033027d022c"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#ab645166633b0002c46951033027d022c">dev::net::SocketApi::ntohl</a></div><div class="ttdeci">static uint32_t ntohl(uint32_t net_uint32)</div><div class="ttdoc">网络字节序转换为主机字节序 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:323</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a14bf28751003dc86e20c60182e771e55"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a14bf28751003dc86e20c60182e771e55">dev::net::SocketApi::setsocketnoblocking</a></div><div class="ttdeci">static bool setsocketnoblocking(sock_t sock, bool on)</div><div class="ttdoc">设置套接字IO模型 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:509</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_adea576bbc110685fbf0bd1faa36dd1f6"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#adea576bbc110685fbf0bd1faa36dd1f6">dev::net::SocketApi::recvfrom</a></div><div class="ttdeci">static ssize_t recvfrom(sock_t sockfd, void *buffer, size_t length, int flags, struct sockaddr *src_addr, socklen_t *addrlen)</div><div class="ttdoc">接受数据报 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:154</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_af8c6ff0f1ef50696e975920048a4ebf9"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#af8c6ff0f1ef50696e975920048a4ebf9">dev::net::SocketApi::select</a></div><div class="ttdeci">static int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)</div><div class="ttdoc">select系统调用 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:481</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_acdaa0a5aadc721422f748f8f931daa53"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#acdaa0a5aadc721422f748f8f931daa53">dev::net::SocketApi::getsockname</a></div><div class="ttdeci">static bool getsockname(sock_t sockfd, struct sockaddr *addr, socklen_t *addrlen)</div><div class="ttdoc">获取套接字本地地址 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:414</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a2e9851418b2c871852e441f73c1df495"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a2e9851418b2c871852e441f73c1df495">dev::net::SocketApi::accept</a></div><div class="ttdeci">static sock_t accept(sock_t sockfd, struct sockaddr *addr, socklen_t *addrlen)</div><div class="ttdoc">接收监听套接字上的连接 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:102</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_ac30763c26a24cd674efa9e6804d9e448"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#ac30763c26a24cd674efa9e6804d9e448">dev::net::SocketApi::getaddrinfo</a></div><div class="ttdeci">static bool getaddrinfo(const char *host, const char *service, const struct addrinfo *hints, struct addrinfo **result)</div><div class="ttdoc">获取指定主机名和服务名的套接字地址列表 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:374</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_ab9e728b6cb0b7932e73acbb250489e25"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#ab9e728b6cb0b7932e73acbb250489e25">dev::net::SocketApi::bind</a></div><div class="ttdeci">static bool bind(sock_t sockfd, const struct sockaddr *addr, socklen_t addrlen)</div><div class="ttdoc">绑定套接字到指定地址 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:79</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_af2941c088aaa168f045e516f1710e54b"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#af2941c088aaa168f045e516f1710e54b">dev::net::SocketApi::setsocketlinger</a></div><div class="ttdeci">static bool setsocketlinger(sock_t sock, bool on)</div><div class="ttdoc">设置套接字Linger选项 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:528</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_aca13c6bb87f3118f3dd2c008238e3a5a"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#aca13c6bb87f3118f3dd2c008238e3a5a">dev::net::SocketApi::shutdown</a></div><div class="ttdeci">static bool shutdown(sock_t sockfd, int how)</div><div class="ttdoc">关闭套接字一端 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:139</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a6137e6bc83ca8599a0e87c7534808c62"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a6137e6bc83ca8599a0e87c7534808c62">dev::net::SocketApi::getnameinfo</a></div><div class="ttdeci">static bool getnameinfo(const struct sockaddr *addr, socklen_t addrlen, char *host, size_t hostlen, char *service, size_t servlen, int flags)</div><div class="ttdoc">获取指定套接字地址的主机名和服务名 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:400</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a2dadafc2cc647d97ab5091e8dc12195c"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a2dadafc2cc647d97ab5091e8dc12195c">dev::net::SocketApi::htons</a></div><div class="ttdeci">static uint16_t htons(uint16_t host_uint16)</div><div class="ttdoc">主机字节序转换为网络字节序 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:293</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_aebfd2453f8424cebb9dc467d1cea40dd"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#aebfd2453f8424cebb9dc467d1cea40dd">dev::net::SocketApi::setsockopt</a></div><div class="ttdeci">static bool setsockopt(sock_t sockfd, int level, int optname, const void *optval, socklen_t optlen)</div><div class="ttdoc">设置套接字选项 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:461</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a468438c9663cdc534e3bf628c29e7c75"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a468438c9663cdc534e3bf628c29e7c75">dev::net::SocketApi::socket</a></div><div class="ttdeci">static sock_t socket(int domain, int type, int protocol=0)</div><div class="ttdoc">创建一个套接字 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:67</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a191d49266fd9aa8149240009fa204e98"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a191d49266fd9aa8149240009fa204e98">dev::net::SocketApi::inet_pton</a></div><div class="ttdeci">static int inet_pton(int domain, const char *src_str, void *addrptr)</div><div class="ttdoc">转换点分十进制表示的地址为二进制格式 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:335</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a508935c561a3841e65d6a7e794503758"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a508935c561a3841e65d6a7e794503758">dev::net::SocketApi::getsockopt</a></div><div class="ttdeci">static bool getsockopt(sock_t sockfd, int level, int optname, void *optval, socklen_t *optlen)</div><div class="ttdoc">获取套接字选项 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:442</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a4dd6d37153baf0f3b28a1a86e9e3513b"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a4dd6d37153baf0f3b28a1a86e9e3513b">dev::net::SocketApi::ntohs</a></div><div class="ttdeci">static uint16_t ntohs(uint16_t net_uint16)</div><div class="ttdoc">网络字节序转换为主机字节序 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:313</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a74d39e1ca0169a15f8e4cc6c6f9756ab"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a74d39e1ca0169a15f8e4cc6c6f9756ab">dev::net::SocketApi::sendto</a></div><div class="ttdeci">static ssize_t sendto(sock_t sockfd, void *buffer, size_t length, int flags, struct sockaddr *dest_addr, socklen_t addrlen)</div><div class="ttdoc">发送数据报 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:176</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html">dev::net::SocketApi</a></div><div class="ttdoc">本地套接字函数wrapper </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:57</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_api_html_a4ac36cc16daf7f35ac40e70fdd52391b"><div class="ttname"><a href="classdev_1_1net_1_1_socket_api.html#a4ac36cc16daf7f35ac40e70fdd52391b">dev::net::SocketApi::connect</a></div><div class="ttdeci">static bool connect(sock_t sockfd, const struct sockaddr *addr, socklen_t addrlen)</div><div class="ttdoc">使用指定套接字连接到服务器 </div><div class="ttdef"><b>Definition:</b> SocketApi.hpp:114</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_5fc0168d11760b9445bd29fa15d9290f.html">dev</a></li><li class="navelem"><a class="el" href="dir_1ca75188a6074d2843e8fd5d982c3101.html">dev</a></li><li class="navelem"><a class="el" href="dir_cea828ca1984caf90af75ecf8a99968a.html">net</a></li><li class="navelem"><b>SocketApi.hpp</b></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.10 </li>
  </ul>
</div>
</body>
</html>
